
from rest_framework import serializers
from goods.models import GoodsVisitCount
# 定义一个序列化器对GoodsVisitCount模型类序列化成
# category和count两个字段

class GoodsVisitModelSerializer(serializers.ModelSerializer):
    # 重新定义成StringRelatedField
    # 目的：修改自定映射来对PrimaryKeyRelatedField,因为业务需求是将
    # 该字段序列化成主表对象对名称而非主键
    category = serializers.StringRelatedField()

    class Meta:
        model = GoodsVisitCount
        fields = [
            "category",
            "count"
        ]